﻿<Window x:Class="ProductKeysWin.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ProductKeysWin" 
    Title="Product Key Manager" Height="387" Width="446" Loaded="WindowOnLoaded" Background="Silver" >
    <Window.Resources>
        <local:DecimalToPercentConverter x:Key="decimalToPercentConverter"/>
        <local:VisibilityConverter x:Key="visibilityConverter"/>
        <Style x:Key="{x:Type ListBoxItem}" TargetType="{x:Type ListBoxItem}">
            <Setter Property="OverridesDefaultStyle" Value="true" />
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="BorderBrush" Value="Transparent" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="HorizontalContentAlignment" Value="Left" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="Padding" Value="3" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Border
              Background="{TemplateBinding Background}" 
              BorderBrush="{TemplateBinding BorderBrush}" 
              BorderThickness="{TemplateBinding BorderThickness}" 
              Padding="{TemplateBinding Padding}">
                            <ContentPresenter x:Name="ContentSite" 
                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                                            <LinearGradientBrush.GradientStops>
                                                <GradientStop Offset="0" Color="#F9F9F9"/>
                                                <GradientStop Offset="1" Color="#E9E9E9"/>
                                            </LinearGradientBrush.GradientStops>
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="BorderBrush" Value="Silver" />
                                <Setter Property="Foreground" Value="Black"/>
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsSelected" Value="true" />
                                    <Condition Property="Selector.IsSelectionActive" 
                             Value="false" />
                                </MultiTrigger.Conditions>
                                <Setter Property="Background" Value="#F8F8F8" />
                                <Setter Property="BorderBrush" Value="#E0E0E0" />
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="false">
                    <Setter Property="Foreground" Value="Gray" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <DockPanel>
        <Menu DockPanel.Dock="Top" Foreground="White">
            <Menu.Background>
                <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                    <LinearGradientBrush.RelativeTransform>
                        <TransformGroup>
                            <TranslateTransform X="-0.5" Y="-0.5"/>
                            <ScaleTransform ScaleX="1" ScaleY="1"/>
                            <SkewTransform AngleX="0" AngleY="0"/>
                            <RotateTransform Angle="90.0172795589426"/>
                            <TranslateTransform X="0.5" Y="0.5"/>
                            <TranslateTransform X="-0.0015136743804197244" Y="-0.19736842105263153"/>
                        </TransformGroup>
                    </LinearGradientBrush.RelativeTransform>
                    <LinearGradientBrush.GradientStops>
                        <GradientStop Color="Black" Offset="0.0"/>
                        <GradientStop Color="#565656" Offset="1"/>
                    </LinearGradientBrush.GradientStops>
                </LinearGradientBrush>
            </Menu.Background>
            <MenuItem Header="_File">
                <MenuItem Click="NewButtonClicked" Header="_New" Foreground="Black"/>
                <Separator/>
                <MenuItem Header="_Import" Click="FileMenuImportPkmXmlClicked" Foreground="Black"/>
                <MenuItem Header="E_xport" Foreground="Black">
                    <MenuItem Click="FileMenuExportMsdnPkmClicked" Header="Export _PKM XML" Foreground="Black"/>
                    <MenuItem Click="FileMenuExportMsdnXmlClicked" Header="Export _MSDN XML" Foreground="Black"/>
                </MenuItem>
                <Separator/>
                <MenuItem Click="FileMenuExitClicked" Header="_Exit" Foreground="Black"></MenuItem>
            </MenuItem>
            <MenuItem Name="menuEdit" IsEnabled="False" Click="EditButtonClicked" Header="_Edit" />
            <MenuItem Header="_Sort">
                <MenuItem Header="Name" Foreground="Black">
                    <MenuItem Name="SortNameNone" Click="OnNameSort" Header="None" IsCheckable="True" IsChecked="True" Foreground="Black"/>
                    <MenuItem Name="SortNameAsc" Click="OnNameSort" Header="Ascending" IsCheckable="True" Foreground="Black"/>
                    <MenuItem Name="SortNameDsc" Click="OnNameSort" Header="Descending" IsCheckable="True" Foreground="Black"/>
                </MenuItem>
            </MenuItem>
            <MenuItem Header="_Tools">
                <MenuItem Header="_Purge DB" Click="ToolsPurgeDbClicked" Foreground="Black"/>
            </MenuItem>
            <MenuItem Header="_Help">
                <MenuItem Header="_About" Click="MenuHelpAboutClicked" Foreground="Black">
                    <MenuItem.Icon>
                        <Image Source="Icon.ico" Width="16" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>
        </Menu>
        <ToolBar Name="tbarEditBar" DockPanel.Dock="Bottom">
            <ToolBar.Background>
                <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                    <LinearGradientBrush.RelativeTransform>
                        <TransformGroup>
                            <TranslateTransform X="-0.5" Y="-0.5"/>
                            <ScaleTransform ScaleX="1" ScaleY="1"/>
                            <SkewTransform AngleX="0" AngleY="0"/>
                            <RotateTransform Angle="90.0172795589426"/>
                            <TranslateTransform X="0.5" Y="0.5"/>
                            <TranslateTransform X="-0.0015136743804197244" Y="-0.19736842105263153"/>
                        </TransformGroup>
                    </LinearGradientBrush.RelativeTransform>
                    <LinearGradientBrush.GradientStops>
                        <GradientStop Color="Black" Offset="0.0"/>
                        <GradientStop Color="#565656" Offset="1"/>
                    </LinearGradientBrush.GradientStops>
                </LinearGradientBrush>
            </ToolBar.Background>
            <Button Click="NewButtonClicked">
                <Image Source="add_24.png" Width="24" Height="24"/>
                <Button.ToolTip>
                    <StackPanel>
                        <Label FontWeight="Bold" Foreground="Orange">
                            <Label.Background>

                                <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                                    <LinearGradientBrush.RelativeTransform>
                                        <TransformGroup>
                                            <TranslateTransform X="-0.5" Y="-0.5"/>
                                            <ScaleTransform ScaleX="1" ScaleY="1"/>
                                            <SkewTransform AngleX="0" AngleY="0"/>
                                            <RotateTransform Angle="90.0172795589426"/>
                                            <TranslateTransform X="0.5" Y="0.5"/>
                                            <TranslateTransform X="-0.0015136743804197244" Y="-0.19736842105263153"/>
                                        </TransformGroup>
                                    </LinearGradientBrush.RelativeTransform>
                                    <LinearGradientBrush.GradientStops>
                                        <GradientStop Color="Black" Offset="0.0"/>
                                        <GradientStop Color="#565656" Offset="1"/>
                                    </LinearGradientBrush.GradientStops>
                                </LinearGradientBrush>
                            </Label.Background>
                            New
                        </Label>
                        <TextBlock Padding="10" TextWrapping="WrapWithOverflow" Width="200">
						Add a new product and key(s)
					</TextBlock>
                    </StackPanel>
                </Button.ToolTip>
            </Button>
            <Separator/>
            <Button Name="toolbEdit" IsEnabled="False" Click="EditButtonClicked">
                <Image Source="edit_24.png" Width="24" Height="24"/>
                <Button.ToolTip>
                    <StackPanel>
                        <Label FontWeight="Bold" Foreground="Orange">
                            <Label.Background>

                                <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                                    <LinearGradientBrush.RelativeTransform>
                                        <TransformGroup>
                                            <TranslateTransform X="-0.5" Y="-0.5"/>
                                            <ScaleTransform ScaleX="1" ScaleY="1"/>
                                            <SkewTransform AngleX="0" AngleY="0"/>
                                            <RotateTransform Angle="90.0172795589426"/>
                                            <TranslateTransform X="0.5" Y="0.5"/>
                                            <TranslateTransform X="-0.0015136743804197244" Y="-0.19736842105263153"/>
                                        </TransformGroup>
                                    </LinearGradientBrush.RelativeTransform>
                                    <LinearGradientBrush.GradientStops>
                                        <GradientStop Color="Black" Offset="0.0"/>
                                        <GradientStop Color="#565656" Offset="1"/>
                                    </LinearGradientBrush.GradientStops>
                                </LinearGradientBrush>
                            </Label.Background>
                            Edit
                        </Label>
                        <TextBlock Padding="10" TextWrapping="WrapWithOverflow" Width="200">
						Edit the selected product and add or remove keys.
					</TextBlock>
                    </StackPanel>
                </Button.ToolTip>
            </Button>
            <Separator/>
            <Button Click="DeleteButtonClicked">
                <Image Source="delete_24.png" Width="24" Height="24"/>
                <Button.ToolTip>
                    <StackPanel>
                        <Label FontWeight="Bold" Foreground="Orange">
                            <Label.Background>

                                <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                                    <LinearGradientBrush.RelativeTransform>
                                        <TransformGroup>
                                            <TranslateTransform X="-0.5" Y="-0.5"/>
                                            <ScaleTransform ScaleX="1" ScaleY="1"/>
                                            <SkewTransform AngleX="0" AngleY="0"/>
                                            <RotateTransform Angle="90.0172795589426"/>
                                            <TranslateTransform X="0.5" Y="0.5"/>
                                            <TranslateTransform X="-0.0015136743804197244" Y="-0.19736842105263153"/>
                                        </TransformGroup>
                                    </LinearGradientBrush.RelativeTransform>
                                    <LinearGradientBrush.GradientStops>
                                        <GradientStop Color="Black" Offset="0.0"/>
                                        <GradientStop Color="#565656" Offset="1"/>
                                    </LinearGradientBrush.GradientStops>
                                </LinearGradientBrush>
                            </Label.Background>
                            Delete
                        </Label>
                        <TextBlock Padding="10" TextWrapping="WrapWithOverflow" Width="200">
						Permanently remove the selected product and all associated keys.
					</TextBlock>
                    </StackPanel>
                </Button.ToolTip>
            </Button>
            <Separator/>
            <TextBox Name="txtSearch" AcceptsReturn="False" KeyDown="SearchKeyDown" Width="150"/>
            <CheckBox Name="chkSearch" Checked="OnSearch" Unchecked="OnUnSearch">
                <Image Source="arrow-forward_24.png" Width="24" Height="24"/>
                <CheckBox.ToolTip>
                    <StackPanel>
                        <Label FontWeight="Bold" Foreground="Orange">
                            <Label.Background>

                                <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                                    <LinearGradientBrush.RelativeTransform>
                                        <TransformGroup>
                                            <TranslateTransform X="-0.5" Y="-0.5"/>
                                            <ScaleTransform ScaleX="1" ScaleY="1"/>
                                            <SkewTransform AngleX="0" AngleY="0"/>
                                            <RotateTransform Angle="90.0172795589426"/>
                                            <TranslateTransform X="0.5" Y="0.5"/>
                                            <TranslateTransform X="-0.0015136743804197244" Y="-0.19736842105263153"/>
                                        </TransformGroup>
                                    </LinearGradientBrush.RelativeTransform>
                                    <LinearGradientBrush.GradientStops>
                                        <GradientStop Color="Black" Offset="0.0"/>
                                        <GradientStop Color="#565656" Offset="1"/>
                                    </LinearGradientBrush.GradientStops>
                                </LinearGradientBrush>
                            </Label.Background>
                            Product Search
                        </Label>
                        <TextBlock Padding="10" TextWrapping="WrapWithOverflow" Width="200">
						Product Key Manager searches product names by keyword.
					</TextBlock>
                        <Line Stroke="Black" StrokeThickness="1" X2="200"/>
                        <Label FontWeight="Bold">Example</Label>
                        <TextBlock Padding="10" TextWrapping="WrapWithOverflow" Width="200">
						"small business" will return any results such with small and business.
					</TextBlock>
                    </StackPanel>
                </CheckBox.ToolTip>
            </CheckBox>
        </ToolBar>
        <ListBox Name="listProdKeys" SelectionChanged="listProdKeys_SelectionChanged" MouseDoubleClick="listProdKeys_DoubleClicked" Foreground="Orange" KeyDown="ListBoxKeyDown"  ItemsSource="{Binding}" SelectionMode="Single">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical">
                        <StackPanel Orientation="Horizontal">
                            <Label Content="{Binding Path=Name}" FontWeight="SemiBold" Foreground="Orange"/>
                            <Label FontWeight="SemiBold" Content="Keys: "/>
                            <Label FontWeight="Normal" Content="{Binding Path=Keys.Count}"/>
                            <ProgressBar Visibility="{Binding Mode=OneWay, Converter={StaticResource visibilityConverter}, Path=SearchSimilarity}" Height="10" Width="30" Maximum="1" Minimum="0"  Value="{Binding Path=SearchSimilarity}"/>
                            <Label Visibility="{Binding Mode=OneWay, Converter={StaticResource visibilityConverter}, Path=SearchSimilarity}" Content="{Binding Mode=OneWay, Converter={StaticResource decimalToPercentConverter}, Path=SearchSimilarity}"/>
                            <Label FontWeight="SemiBold" Visibility="Collapsed" Content="Quick Notes: "/>
                            <Label FontWeight="Normal" Visibility="Collapsed" Content="{Binding Path=QuickNotes}"/>
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </DockPanel>
</Window>
